package kontrol;

import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class login extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        kontrol.Proses proses = new Proses();
        String req1 = req.getParameter("class");
        String pass = null;
        String id= null;
//        String class2 = null;
//        resp.getWriter().println("asas");
//        try {
//            class2 = proses.isintablestaff(req.getParameter("userName"));
//        } catch (SQLException ex) {
//            Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
//        }
        try {
            pass = proses.admin1(req.getParameter("id"));
        } catch (SQLException ex) {
            Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            id = proses.admin2(req.getParameter("id"));
        } catch (SQLException ex) {
            Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
        }

        if (id == null) {
            RequestDispatcher rd = req.getRequestDispatcher("garasimobil.jsp");
            rd.forward(req, resp);
        } else {
            {
//                if (class2.matches("Staff")) {
                 if (req.getParameter("password").matches(pass) && req.getParameter("id").matches(id)) {
                     RequestDispatcher rd = req.getRequestDispatcher("uploadmobil.jsp");
                     rd.forward(req, resp);
                 } else {
                     RequestDispatcher rd = req.getRequestDispatcher("garasimobil.jsp");
                     rd.forward(req, resp);
                 }
//              else {
//                 RequestDispatcher rd = req.getRequestDispatcher("LOGIN.jsp");
//                 rd.forward(req, resp);
//                 }
            }
            
        }
    }

//    @Override
//    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
//    }
}
